<?php

declare (strict_types=1);
namespace App\Model;

use App\Traits\ModelLabelTrait;
use Hyperf\Database\Model\SoftDeletes;
use Hyperf\DbConnection\Model\Model;
/**
 * @property int $id 
 * @property int $user_id 
 * @property int $position_id 
 * @property int $status 
 * @property string $verify_time 
 * @property string $rectify_images 
 * @property string $rectify_txt 
 * @property string $lng 
 * @property string $lat 
 * @property \Carbon\Carbon $created_at 
 * @property \Carbon\Carbon $updated_at 
 * @property string $deleted_at 
 */
class PositionSupervise extends Model
{
    use SoftDeletes, ModelLabelTrait;
    /**
     * The table associated with the model.
     *
     * @var string
     */
    protected $table = 'position_supervise';
    /**
     * The attributes that are mass assignable.
     *
     * @var array
     */
    protected $fillable = [
        'user_id',
        'position_id',
        'lng',
        'lat',
        'status',
        'verify_time',
        'rectify_images',
        'rectify_txt',
        'mask_txt'
    ];

    protected $appends=[
        'status_label'
    ];
    /**
     * The attributes that should be cast to native types.
     *
     * @var array
     */
    protected $casts = [
        'id' => 'int',
        'user_id' => 'integer',
        'position_id' => 'integer',
        'status' => 'integer',
        'allscore' => 'number',
        'final_score'=> 'number',
        'created_at' => 'datetime',
        'updated_at' => 'datetime'
    ];

    const STATUS_DEFAULT = 0;
    const STATUS_WAITING = 1;
    const STATUS_REPLY = 2;
    const STATUS_DONE = 3;
    const STATUS_SCORE = 4;
    const STATUS_FAIL = -1;

    const STATUS_LABELS = [
        self::STATUS_DEFAULT => '未提交',
        self::STATUS_WAITING => '受理中',
        self::STATUS_REPLY => '整改中',
        self::STATUS_DONE => '已完成',
        self::STATUS_SCORE => '已评分',
        self::STATUS_FAIL => '审核失败'
    ];

    public function getStatusLabelAttribute(){
        return self::getLabel('status',$this->status);
    }

    public function position(){
        return $this->belongsTo(PointPosition::class,'position_id','id');
    }
}